<?php

//UMA new
namespace App\Http\Middleware;

use Closure;
use Carbon\Carbon;
use App\Models\ContactInfo;

class RefactorContactData
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        // $contact = ContactInfo::where("customer_history_id", $request->customer_history_id)->latest()->first();

        // if($contact && $contact->isRepeatSubmit()) {
        //     return response()->json(['error' => 'pls dont submit repeatly'], 422);
        // }

        if (!is_array($request->first_contact_date)) {
            $request->merge(['first_contact_date' => [
                'date' => $request->first_contact_date,
                'time' => $request->first_contact_time,
            ]]);
        }
        if (!is_array($request->second_contact_date)) {
            $request->merge(['second_contact_date' => [
                'date' => $request->second_contact_date,
                'time' => $request->second_contact_time,
            ]]);
        }
        return $next($request);
    }
}
